$(function () {
    // body...
    localStorage.indexName = titleIndex;

     $.ajax({
        url: 'http://47.89.20.150/czlycms/index.php?m=Web&a=getStock',
        type: 'GET',
        dataType: 'JSONP'
    })
    .done(function(data) {
        console.log("success");
        console.log(data);
        $('#STOCK_word').find('.p2').text(data.time);
        $('#STOCK_word').find('.p3').text('HK＄'+data.g_price);
        $('#STOCK_word').find('.p4').text(isIfFun(data.isUp)+data.stock1+' | '+isIfFun(data.isUp)+data.stock2);
        function isIfFun(data){
            if (data >0) {
                return '+ ';
            }else if(data < 0){
                return '- ';
            }else if (data == 0) {
                return ' ';
            }
        }
    })
    .fail(function() {
        console.log("error");
    });


    $.ajax({
        url: 'http://47.89.20.150/czlycms/index.php?m=Web&a=index',
        type: 'GET',
        dataType: 'JSONP'
    })
    .done(function(data) {
        console.log("success");
        console.log(data);
        bannerslides(data.slides);
        indexArticle(data.article);
        PhotosFun(data.photo);

        DocumentFun(data.Document);

        linksFun(data.link);
        figureFun(data.figure);
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
        callSweiper();
        windowsrloo();
    });


  

//轮播图

  function bannerslides(slides){
    var IndBanerC = $('#IndBanerC');
    var html = '';
    for (var i = 0; i < slides.length; i++) {
        var cn = '<div class="swiper-slide">'+
                    '<img src="'+slides[i].image_url+'">'+
                    '<div class="banerWordCn">'+
                       ' <p class="ani ind1 " swiper-animate-effect="fadeInUp" swiper-animate-duration="0.5s" swiper-animate-delay="0.3s">'+slides[i].title+'</p>'+
                        '<p class="ani ind2 " swiper-animate-effect="fadeInUp" swiper-animate-duration="0.5s" swiper-animate-delay="0.6s">'+slides[i].title2+'</p>'+
                       ' <p class="ani ind3" swiper-animate-effect="fadeInUp" swiper-animate-duration="0.5s" swiper-animate-delay="0.9s">'+slides[i].title3+'</p>'+
                        '<a class="ani" swiper-animate-effect="fadeInUp" swiper-animate-duration="0.5s" swiper-animate-delay="1.2s" href="'+slides[i].url+'">Learn More</a>'+
                    '</div>'+
                '</div>';
                html+=cn;
    }
    IndBanerC.html(html);
  }
//轮播图 end




// 文章和新闻

  function indexArticle(Article){
        // var dari = ['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'];
        var dari = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
        ArticleFun(Article[18]);
        FEATUREDFun(Article[22]);

        function ArticleFun(data){
            var ANNList = $('#ANNList');
            var html = '';
            var moer = '<li class="clearfloat"><a href="pageList.html?cate_id=18" class="bot">MORE</a> </li>';
            var indOne = 0;
            if (data.length >=5) {
                indOne=4;
            }else{
               indOne = data.length-1;
            }
            for (var i = 0; i < indOne; i++) {
                var issueDate = data[i].issueDate

                var nian = (issueDate.split("-"))[0];
                var yue = (issueDate.split("-"))[1];
                var ri = (issueDate.split("-"))[2];

                var cn = '<li class="clearfloat">'+
                           ' <div class="timeCom">'+dari[(yue-1)] +' '+ri+', '+nian+'</div>'+
                            '<div class="RigCon">'+
                                '<a href="article.html?article_id='+data[i].article_id+'">'+
                                    '<p>'+data[i].title+'</p>'+
                                    '<span>PRESS RELEASE</span>'+
                                '</a>'+
                            '</div>'+
                        '</li>';
                html+=cn;
            }
            ANNList.html(html +moer);
        }

        function FEATUREDFun(data){
            var newsList = $('#newsList');
            var html = '';
            for (var j = 0; j <= 2; j++) {
                var issueDate = data[j].issueDate
                var nian = (issueDate.split("-"))[0];
                var yue = (issueDate.split("-"))[1];
                var ri = (issueDate.split("-"))[2];
                
                var cn = '<li><a href="article.html?article_id='+data[j].article_id+'"><div class="imgc"><img src="'+data[j].image_url+'"><div class="hoverCn"><i class="iconfont">&#xe658;</i></div></div><div class="time">'+dari[(yue-1)] +' '+ri+', '+nian+'</div><div class="word">'+data[j].title+'</div></a></li>';


                     html+=cn;
            }
            newsList.html(html);
        }
  }

// 文章和新闻 end



// 相册
  function PhotosFun(data){
    var photosNav = $('#photosNav');
    var html = '';
    console.log(data);
    for(var i in data){
        console.log(i);
        PhotosNavArray.push(i);
        var cn = '<a href="javascript:void(0);" data-name="'+i+'">'+data[i].title+'</a>';
        html+=cn;

    }
    // console.log(PhotosNavArray);
    photosNav.html(html);
    photosNav.find('a').eq(0).addClass('active');

    PhotosObj = data;
    PhotosFunC(photosNav.find('a').eq(0).attr('data-name'));

  }
    

// 相册 end



// 相册方法

function PhotosFunQie(){
    var photosNav = $('#photosNav');
    photosNav.on('click','a',function(){
        var string = $(this).attr('data-name');
        $(this).addClass('active').siblings().removeClass('active');
        PhotosFunC(string)
    })
}

PhotosFunQie()


function PhotosFunC(string){
    var photosCon = $('#photosCon');
    var data = PhotosObj[string].photo_list;
    html = '';
    for (var i = 0; i < data.length; i++) {
        var cn = '';
        if (i == 0 || i == 3) {
            cn = '<li>'+
                    '<a href="javascript:void(0);" class="imgC">'+
                        '<img class="photo" data-in="'+i+'" src="'+data[i].image_url+'">'+
                        '<div class="hoverCn">'+
                            '<div class="hed">'+data[i].title+'</div>'+
                            '<p>'+data[i].describe+'</p>'+
                            '<span class="iconCn"><i class="iconfont">&#xe601;</i></span>'+
                        '</div>'+
                   ' </a>'+
                '</li>';
            
        }if (i == 1 || i == 4) {
            if (data.length <= (i+1)) {
                cn = '<li>'+
                    '<a href="javascript:void(0);" class="imgT">'+
                        '<img class="photo" data-in="'+i+'" src="'+data[i].image_url+'">'+
                        '<div class="hoverCn">'+
                            '<div class="hed">'+data[i].title+'</div>'+
                            '<p>'+data[i].describe+'</p>'+
                            '<span class="iconCn"><i class="iconfont">&#xe601;</i></span>'+
                        '</div>'+
                    '</a>'+
                '</li>';
            }else{
                cn = '<li>'+
                    '<a href="javascript:void(0);" class="imgT">'+
                        '<img class="photo" data-in="'+i+'" src="'+data[i].image_url+'">'+
                        '<div class="hoverCn">'+
                            '<div class="hed">'+data[i].title+'</div>'+
                            '<p>'+data[i].describe+'</p>'+
                            '<span class="iconCn"><i class="iconfont">&#xe601;</i></span>'+
                        '</div>'+
                    '</a>'+
                    '<a href="javascript:void(0);" class="imgB">'+
                        '<img class="photo" data-in="'+(i+1)+'" src="'+data[i+1].image_url+'">'+
                        '<div class="hoverCn">'+
                            '<div class="hed">'+data[i+1].title+'</div>'+
                            '<p>'+data[i+1].describe+'</p>'+
                            '<span class="iconCn"><i class="iconfont">&#xe601;</i></span>'+
                        '</div>'+
                    '</a>'+
                '</li>';
            }
        }
            
        html+=cn;
    }

    photosCon.html(html)

    PhotosFrameFun();



}

// 相册方法 end




//文件下载
 function DocumentFun(data){
    var DocumensListNCn = $('#DocumensListNCn');
    var html = '';
    for (var i = 0; i <= 3; i++) {
         var cn = '<div class="swiper-slide"><a href="'+data[i].image_url+'">'+
                            '<div class="DOCUL">'+
                                '<div class="head">'+data[i].title+'</div>'+
                                '<p>'+data[i].describe+'</p>'+
                                '<div class="icon"><i class="iconfont">&#xe64e;</i></div>'+
                                '<div class="posback"></div>'+
                            '</div>'+
                       '</a></div>';
        html+=cn;

           
    }
    DocumensListNCn.html(html);
    DOCUMENTSListN();

 }

//文件下载 end


//友情链接 link
    
function linksFun(data){
    var LinksCon = $('#LinksCon');
    var html = '';
    for (var i = 0; i < data.length; i++) {
         var cn = '<div class="swiper-slide"><a href="'+data[i].url+'"><img src="'+data[i].image_url+'"></a></div>';
        html+=cn;

           
    }
    LinksCon.html(html);
    ButLogoListN();
}

//友情链接 link end



// figureFun
function figureFun(data){
    
    var FIGURESlist = $('#FIGURESlist');
    var html = '';
    for (var i = 0; i < data.length; i++) {
         var cn = '<li><div class="came"><span id="counting-'+data[i].figure_id+'"></span>'+ifType(data[i].type)+'</div><p class="name">'+expandEntities(data[i].title)+'</p></li>';
        html+=cn;
           
    }
    FIGURESlist.html(html);


    function ifType(type){
        if (type == "percent") {
            return '%';
        }else{
            return ' ';
        }
    }

    FIGURES(data);


}

// figureFun end



})





// var obj  = {sva:[123,123,123]}

// var string = 'sva';


// console.log(obj.string) ;
